<template>
    <div class="head-wrapper">
        <div class="box1 clearfix">
            <!--这里是logo-->
            <div class="logo">
                <router-link to="/home">
                    <img src="@/assets/img/logo.png" />
                </router-link>
            </div>
            <!--这里是搜索和推荐栏-->
            <div class="box2">
                <div class="search clearfix">
                    <!--这里是搜索框对应的表单-->
                    <form action="javascript:" method="post" class="clearfix">
                        <input type="text" class="search-text" v-model="keyword" />
                        <input type="submit" value="搜索" class="search-button" @click="goSearch"/>
                    </form>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            keyword:"",
        }
    },
    mounted() {
        this.keyword = this.$route.params.keyword;
    },
    methods: {
        goSearch(){
            event.preventDefault();
            if(!this.keyword.trim()){
                this.$message({
                    message:"搜索内容不能为空",
                    type:"warning"
                })
                return;
            }
            this.$router.push({
                name:"search",
                params:{
                    keyword:this.keyword
                }
            })
        },
    },
};
</script>

<style scoped>
.head-wrapper {
    width: 100%;
    height: 120px;
    background-color: #fff;
}

.box1 {
    position: relative;
    width: 1200px;
    height: 100%;
    margin: 0 auto;
}

/*设置头部logo样式*/
.box1 .logo {
    position: absolute;
    width: 180px;
    height: 50px;
    top: 0;
    bottom: 0;
    margin: auto;
}

.box1 .logo a img {
    display: block;
    width: 180px;
    height: 50px;
}

/*设置头部搜索框样式*/
.box1 .box2 {
    /*float: left;*/
    /*margin-left: 121px;*/
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
    width: 700px;
    height: 90px;
}

.box2 .search {
    background-color: rgb(232, 44, 41);
    position: absolute;
    top: 0;
    bottom: 0;
    margin: auto;
    height: 40px;
}

.box2 .search form .search-text {
    float: left;
    width: 576px;
    height: 20px;
    padding: 8px 8px 8px 14px;
    border: 2px solid rgb(232, 44, 41);
    border-right: 0;
    /*取消文本框被选中时出现的边框（实际上是轮廓）*/
    outline: none;
}

.box2 .search form .search-button {
    float: left;
    width: 100px;
    height: 40px;
    border: none;
    background-color: rgb(232, 44, 41);
    font-size: 20px;
    color: white;
    line-height: 40px;
    padding: 0;
}
</style>